<?php
$baseRSSURL = "http://www.supremerssnews.com/";

$dbh2 = pg_connect("dbname=$pg_db host=$pg_host user=$pg_username password=$pg_password");
$username = pg_escape_string($_SESSION['userName']);

$query = "SELECT s.title FROM stores AS s JOIN resellers AS r USING(reseller_id) WHERE r.name='$username'";
$result = pg_query($dbh2, $query);

if (!pg_num_rows($result)) {
	$errorMsg = translate('int_error');
	include_once('errorMsg.html');
	exit();
}

$row = pg_fetch_assoc($result);
$StoreName = $row['title'];

$query = "SELECT password FROM resellers WHERE name='" . pg_escape_string($username) . "'";
$result = pg_query($query);
$row = pg_fetch_assoc($result);
$md5 = md5($row['password']);
$username = urlencode($username);
unset($query);

$params[sid] = $sid;
$params[action] = 'news_instructions';
$instrucions_url = "$baseURL/$webDIR/?".encode_params($params);

$rss_file = $baseRSSURL . "?mode=rp&username=$username&md5=$md5";
?>
<script type="text/javascript">
	function switch_news(i) {
		var news = document.getElementById('news_' + i);
		
		if (news.style.display == "none") {
			news.style.display = "";
		} else {
			news.style.display = "none";
		}
	}
</script>
<table width="550" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td>
			<p><strong>News Manager</strong></p>
			<p>When it is necessary, news is being sent to your clients on behalf of your StoreName ('<?=$StoreName?>'). Depending on the event we'd like to inform your clients about, news is being spread:</p>
			<blockquote>
				a. <strong>globally</strong> - to all clients on all servers<br />
				b. <strong>partially</strong> - to a given server or group of servers<br />
				c. <strong>personally</strong> - to a given account or a set of accounts
			</blockquote>
			If you wish you can use our RSS feed and display the news snippets on your store. We recommend that you do so, because your potential clients will be able to learn more about the offered services.
			<br /><br />
			The RSS feed's url is: <strong>http://www.supremerssnews.com/?mode=rp&username= <font color="Red">%%USERNAME%%</font> &md5= <font color="Red">%%MD5%%</font> </strong>
			<br /><br />
			where <font color="Red">%%USERNAME%%</font> is your user name ( <strong><?=$username?></strong> ) and <font color="Red">%%MD5%%</font> is <strong><?=$md5?></strong>
			<br /><br /><br />
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td width="100"><a type="text/xml" href="<?=$rss_file?>"><img src="news/images/btn_view_rss.gif" alt="View RSS" width="90" height="26" border="0"></a></td>
					<td>Instructions How To Insert RSS Feed Into A Web Page:<br>
						<a href="<?=$instrucions_url?>">Instructions 1</a> : <a href="http://www.feedforall.com/free-php-script.htm" target="_blank">Instructions 2</a></td>
				</tr>
			</table>
			<br /><br />
			<div style="background-color: #dcdcdc"><strong>RSS News Preview</strong></div>
			<br />

<?php
ob_start();
@readfile($rss_file);
$xml_str = ob_get_contents();
ob_end_clean();

if ($dom = @domxml_open_mem($xml_str)) {
	$doc = $dom->document_element();

	$items = $doc->get_elements_by_tagname('item');

	$i = 1;
	$news = "";
	foreach ($items as $item) {
		$titles = $item->get_elements_by_tagname('title');
		$title = $titles[0]->get_content();
		$descriptions = $item->get_elements_by_tagname('description');
		$description = $descriptions[0]->get_content();		

		$news .= "
				<img valign=\"middle\" src=\"news/images/ico_rss_news_preview.gif\" alt=\" \">&nbsp;<a href=\"#$i\" onclick=\"switch_news($i)\"><strong>$title</strong></a><br>
				<div id=\"news_$i\" style=\"display: none\">$description</div>";
		
		$i++;
	}
	
	echo $news;
}
?>
		</td>
	</tr>
</table>
